package com.sgcc.sx.pmos.e_sx_personalcenter.activity;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.sx.pmos.arouter.app.AppArouterPath;
import com.sgcc.sx.pmos.arouter.personalcenter.PersonalCenterArouterPath;
import com.sgcc.sx.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.sx.pmos.common.bean.EventCenter;
import com.sgcc.sx.pmos.common.utils.ArguConstant;
import com.sgcc.sx.pmos.common.utils.UserManager;
import com.sgcc.ln.pmos.common.widget.TitleBar;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.sx.pmos.e_sx_personalcenter.adapter.MessageAdapter;
import com.sgcc.sx.pmos.e_sx_personalcenter.contract.MessageContract;
import com.sgcc.sx.pmos.e_sx_personalcenter.presenter.MessagePresenter;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.ArrayList;
import java.util.List;

/**
 * 消息
 */
@Route(path = PersonalCenterArouterPath.PERSONALCENTER_MESSAGE)
public class MessageActivity extends MvpBaseRecycleActivity<String, MessagePresenter> implements MessageContract.View {

    @Override
    public String getTitleText() {
        return "消息";
    }

    @Override
    protected void initViews() {
        super.initViews();
        title_bar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                goMainActivity();
            }
        });
    }

    @Override
    public void querySuccess() {

    }

    @Override
    public void queryFailed() {

    }

    @Override
    public void onResume() {
        super.onResume();
        onChangePage();
    }

    @Override
    public boolean isBindEventBusHere() {
        return true;
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(EventCenter eventCenter) {
        if (eventCenter.getEventCode() == ArguConstant.LOGOUT) {
            onChangePage();
        }
    }

    private void onChangePage() {
        if (UserManager.isLogin()) {
            ll_content.setVisibility(View.VISIBLE);
            not_login_layout.setVisibility(View.GONE);
        } else {
            View notLoginView = getLayoutInflater().inflate(R.layout.not_login_message_layout, not_login_layout, false);
            TitleBar mTitleBar = (TitleBar) notLoginView.findViewById(R.id.title_bar);
            mTitleBar.setTitle("消息");
            mTitleBar.setRightIcon(R.mipmap.go_main, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    goMainActivity();
                }
            });
            TextView mTvLogin = (TextView) notLoginView.findViewById(R.id.tv_login);
            mTvLogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ARouter.getInstance()
                            .build(AppArouterPath.APP_LOGIN)
                            .navigation();
                }
            });
            not_login_layout.addView(notLoginView);
            not_login_layout.setVisibility(View.VISIBLE);
            ll_content.setVisibility(View.GONE);
        }
    }

    @Override
    protected MessagePresenter createPresenter() {
        return new MessagePresenter();
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new MessageAdapter();
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
//        mPresenter.getCollectionList(listSize, isloading);

        List<String> list = new ArrayList<>();
        loadSuccess(false, list);
    }
}
